package com.sgcc.fj.pmos.e_fj_mall.adapter;


import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.fj.pmos.common.bean.RatioCurveBean;
import com.sgcc.fj.pmos.common.view.LineChartView;
import com.sgcc.pmos.nativesdk.R;

public class PowChartAdapter extends BaseQuickAdapter<RatioCurveBean.Bean, BaseViewHolder> {

    private Context mContext;
      int lastPostion=0;
    public PowChartAdapter(Context context) {
        super(R.layout.item_order_powchart);
        mContext = context;
    }

    public interface OnItemClickListener {
        //条目点击
        void OnItemsClickListener(int position, RatioCurveBean.Bean s,int lastPosotion);
    }

    private OnItemClickListener mOnItemClickListener;

    public void setItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, RatioCurveBean.Bean s) {
        baseViewHolder.setText(R.id.txt_chart_name,s.getRatioName());
//        if(s.isSelect()){
//            baseViewHolder.setBackgroundColor(R.id.root_bg,0xff0092FF);
//        }else{
//            baseViewHolder.setBackgroundColor(R.id.root_bg,0xffffffff);
//        }
        if(s.isSelect()){
            baseViewHolder.setBackgroundResource(R.id.item_bg_re,R.drawable.bg_item_box_select);
        }else{
            baseViewHolder.setBackgroundResource(R.id.item_bg_re,R.drawable.bg_item_box);
        }
        LinearLayout llcontent = baseViewHolder.getView(R.id.ll_content);
        LineChartView lineChartView = new LineChartView(mContext, s.getYAxis());
        llcontent.addView(lineChartView);

        lineChartView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.OnItemsClickListener(getItemPosition(s),s,lastPostion);
                }
                lastPostion = getItemPosition(s);
            }
        });
    }
}
